package com.itheima.mapper;

import com.itheima.pojo.Order;
import com.itheima.pojo.User;
import com.itheima.pojo.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

// 这个接口中的方法都是用来操作多表查询
public interface UserMapperMoreTable {
    // 通过id查询1个用户
    @Select("select * from user where id=#{id};")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "birthday",property = "birthday"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "address",property = "address"),
            @Result(property = "userInfo",column = "id",
            one = @One(select = "findUserInfo")),
            @Result(property = "orders",column = "id",
            many = @Many(select = "findOrders"))
    })
    User findUserById(int uid);

    //通过id查询用户扩展信息
    @Select("select * from user_info where id=#{uid};")
    UserInfo findUserInfo(int uid);

    //通过ID查询当前用户订单
    @Select("select * from `order` where user_id = #{uid}")
    List<Order> findOrders(int uid);


}
